package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pr=tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable Long id){
        TodayBest vo = tanhuaService.personalInfo(id);
        return ResponseEntity.ok(vo);
    }

    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String txt=tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(txt);
    }

    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        //获取userId,转化为String类型
        String obj = map.get("userId").toString();
        //转化为Long类型
        Long userId = Long.valueOf(obj);
        //获取参数,回复的内容
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list=tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable String id){
        tanhuaService.love(Long.valueOf(id));
        return ResponseEntity.ok(null);
    }

    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable String id){
        tanhuaService.unlove(Long.valueOf(id));
        return ResponseEntity.ok(null);
    }

    @GetMapping("/search")
    public ResponseEntity queryNearUser(String gender,
                                        @RequestParam(defaultValue = "2000")String distance){
        List<NearUserVo> vos=tanhuaService.queryNearUser(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
